<?php
class Api
{
    public function __construct()
    {
        // do nothing
    }
    
    private static $instance = null;
    private $apis = array();
    
    public static function load($api_name)
    {
        if(is_null(self::$instance))
            self::$instance = new self;
        
        if(isset(self::$instance->apis[$api_name])){
            return self::$instance->apis[$api_name];
        }else{
            $api_class_name = 'Api_'.ucfirst($api_name);
            
            if(class_exists($api_class_name)){
                self::$instance->apis[$api_name] = new $api_class_name();
                return self::$instance->apis[$api_name];
            }else{
                return null;
            }
        }
    }
    
    public static function getInstance()
    {
        if(is_null(self::$instance)){
            self::$instance = new self;
        }
        return self::$instance;
    }
    
    public function get_apis()
    {
        return $this->apis;
    }
    
    public function releaseApis()
    {
        unset ($this->apis);
    }
}
